import { RuleOptionalStack, RuleParse } from "../type";
import globelRuleParse from './globelRuleParse';

const positionRuleParse: RuleParse = {

	parseType: "position",

	isNested: true,

	preHandle: (parse, rule, char) => { },

	judge: (parse, rule, char) => {
		const ruleSt = rule.select;
		const parseType = parse.top && parse.top.parseType;
		if (char === "^" && parseType !== "switch") {
			rule.push({ ruleType: "position", ruleData: (save, origin, rule, str, index, char, length) => index === 0 });
			parse.push(globelRuleParse);
			return true;
		} else if (char === "$" && parseType !== "switch") {
			rule.push({ ruleType: "position", ruleData: (save, origin, rule, str, index, char, length) => index === length });
			parse.push(globelRuleParse);
			return true;
		}
		return false;
	},

	// [canNested=true]
	handle: (parse, rule, char) => { return false; },
};


export default positionRuleParse;
